<template>
  <page-view :title="title">
    <a-card :bordered="false">
      <detail-list title="个人信息">
        <detail-list-item term="id">{{ data.id }}</detail-list-item>
        <detail-list-item term="姓名">{{ data.name }}</detail-list-item>
        <detail-list-item term="年龄">{{ data.age }}</detail-list-item>
        <detail-list-item term="性别">{{ data.gender === 0 ? '男':'女' }}</detail-list-item>
        <detail-list-item term="证件类型">{{ carTypeFilter(data.carType) }}</detail-list-item>
        <detail-list-item term="证件号">{{ data.carId }}</detail-list-item>
        <detail-list-item term="电话号码">{{ data.phone }}</detail-list-item>
      </detail-list>
      <a-divider class="divider"/>
      <detail-list title="亲属信息">
        <detail-list-item term="姓名">{{ data.contact }}</detail-list-item>
        <detail-list-item term="联系电话">{{ data.emergency }}</detail-list-item>
      </detail-list>
      <a-divider class="divider"/>
      <detail-list title="病情信息">
        <detail-list-item term="部门">{{ departmentFilter(data.department) }}</detail-list-item>
        <detail-list-item term="当前状态">{{ data.state === 0 ? '住院中' : '已出院' }}</detail-list-item>
        <detail-list-item term="主治医生">{{ doctor.name }}</detail-list-item>
        <detail-list-item term="入院日期">{{ data.comeDate }}</detail-list-item>
        <detail-list-item term="病房">{{ data.ward }}</detail-list-item>
        <detail-list-item term="床位">{{ data.bed }}</detail-list-item>
        <detail-list-item term="出院日期">{{ data.state === 0 ? '暂未出院' : data.outDate }}</detail-list-item>
      </detail-list>
      <a-divider class="divider"/>
      <detail-list title="备注信息">
        <detail-list-item term="备注">{{ data.remarks }}</detail-list-item>
      </detail-list>
      <a-divider class="divider"/>
      <detail-list title="其他信息">
        <detail-list-item term="是否城乡医保">{{ data.insurance === 0 ? '是' : '否' }}</detail-list-item>
        <detail-list-item term="是否异地就医">{{ data.allopatry === 0 ? '是' : '否' }}</detail-list-item>
      </detail-list>
      <a-divider style="margin-bottom: 32px"/>
      <a-button style="margin-left: 8px" @click="goBack()">返回</a-button>
    </a-card>
  </page-view>
</template>

<script>
import DetailList from '@/components/tools/DetailList'
import { getDoctor } from '../../api/doctor'
import { carTypeFilter, departmentFilter } from '../../dictionary'

const DetailListItem = DetailList.Item
export default {
  name: 'ShowPatient',
  data () {
    return {
      doctor: {},
      data: this.$store.state.app.show
    }
  },
  components: {
    DetailList,
    DetailListItem
  },
  computed: {
    title () {
      return this.$route.meta.title
    }
  },
  methods: {
    goBack () {
      this.$store.state.app.show = null
      this.$router.push('/patient/index')
    },
    carTypeFilter,
    departmentFilter
  },
  created () {
    getDoctor(this.data.doctor).then(res => {
      this.doctor = res.result
    }).catch(err => {
      console.log('err', err)
    })
  },
  beforeCreate () {
    console.log('state', this.$store.state)
    if (this.$store.state.app.show === null || this.$store.state.app.show === undefined) {
      this.$router.push('/patient/index')
    }
  }
}
</script>

<style lang="less" scoped>
  .title {
    color: rgba(0,0,0,.85);
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 16px;
  }
  .divider {
    margin-bottom: 32px;
  }
</style>
